// 最长公共前缀

// 输入：strs = ["flower","flow","flight"]
// 输出："fl"

/**
 * @param {string[]} strs
 * @return {string}
 */
var longestCommonPrefix = function (strs) {
  const len = strs.length
  let minLen = strs[0].length

  let result = ''

  for (let i = 1; i < len; i++) {
    if (strs[i].length < minLen) {
      minLen = strs[i].length
    }
  }

  for (let i = 0; i < minLen; i++) {
    let curStr = strs[0][i]   // f
    for (let j = 1; j < len; j++) {
      if (strs[j][i] !== curStr) {
        return result
      }
    }
    result += curStr
  }

  return result
};

console.log(longestCommonPrefix(["flower", "flow", "flight"]));
